﻿Imports System.Data.OleDb

Partial Public Class shareDiscussionRepeater
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Dim songID = 
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings _
("ConnectionString").ToString())
        oleDbConn.Open()

        'get value from DiscussionShareMain table

        Dim DiscussionMainStr As String = "Select * from DiscussionShareMain WHERE ([ID] = @ID)"
        Dim DiscusionDbCmd As New OleDbCommand(DiscussionMainStr, oleDbConn)
        DiscusionDbCmd.Parameters.AddWithValue("@ID", Request.QueryString("ID"))
        Dim DiscussionDbread = DiscusionDbCmd.ExecuteReader()
        If DiscussionDbread.HasRows() Then
            DiscussionDbread.Read()
            lblTopic.Text = DiscussionDbread("DiscussionName")
            ' lblSongName.Text = songDbread("songName")
            ' lblAbstract.Text = songDbread("description")
        End If
        DiscussionDbread.Close()
        DiscusionDbCmd.Dispose()

        'get value from DiscussionShareMain table
        Dim DiscussionSubStr As String = "Select * from DiscussionShare WHERE ([DiscussionTitle] = @ID)"
        Dim DiscusionSubDbCmd As New OleDbCommand(DiscussionSubStr, oleDbConn)
        DiscusionSubDbCmd.Parameters.AddWithValue("@ID", Request.QueryString("ID"))
        Dim DiscussionSubDbread = DiscusionSubDbCmd.ExecuteReader()
        If DiscussionSubDbread.HasRows() Then
            DiscussionSubDbread.Read()
            lblUserName.Text = DiscussionSubDbread("UserName")
            lblDate.Text = DiscussionSubDbread("PostedDate")
            lblBody.Text = DiscussionSubDbread("Body")
            ' lblSongName.Text = songDbread("songName")
            ' lblAbstract.Text = songDbread("description")
        End If
        DiscussionSubDbread.Close()
        DiscusionSubDbCmd.Dispose()
        loadDiscussionDetail()
    End Sub

    Protected Function loadDiscussionDetail()
       
        Dim conn1 = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings _
                 ("ConnectionString").ToString())
        conn1.Open()

        Dim postingStr As String = "SELECT * FROM DiscussionShare where [DiscussionTitle]= @ID"
        Dim postingDBcmd As New OleDb.OleDbCommand(postingStr, conn1)
        postingDBcmd.Parameters.AddWithValue("@ID", Request.QueryString("ID"))

        Dim dbread1 = postingDBcmd.ExecuteReader()
        Repeater1.DataSource = dbread1
        Repeater1.DataBind()
        Try
            Return (dbread1)
        Catch ex As Exception
            Return 0
        End Try
    End Function

  
    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
        Dim connShare = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings _
            ("ConnectionString").ToString())
        connShare.Open()

        Dim sqlstr = "INSERT INTO DiscussionShare ([DiscussionTitle],[Body],[UserName],[PostedDate]) VALUES ([@DiscussionTitle],[@Body],[@UserName],[@PostedDate]) "
        Dim newPostsdbcmd As New OleDbCommand(sqlstr, connShare)
        newPostsdbcmd.Parameters.AddWithValue("@DiscussionTitle", Request.QueryString("ID"))
        newPostsdbcmd.Parameters.AddWithValue("@Body", txtBody.Text)
        newPostsdbcmd.Parameters.AddWithValue("@UserName", User.Identity.Name)
        newPostsdbcmd.Parameters.AddWithValue("@PostedDate", DateTime.Now.Date)

        newPostsdbcmd.ExecuteNonQuery()
        loadDiscussionDetail()
    End Sub
End Class